<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
        <%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String userid=request.getParameter("userid");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--<base href="http://api.xszhuan.com/TianciXSZ/">--><base href=".">
<title>学生赚互动交流</title>
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,initial-scale=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="format-detection" content="telephone=no">
<meta content="false" id="twcClient" name="twcClient">
<link href="<%=basePath %>interact/css/global.css" rel="stylesheet" type="text/css">

<style type="text/css">
 /*btnbox*/
.lay-ft-btn{border-bottom:solid 2px #1bb3e4;background:url() repeat-x left top; background-size:auto 38px;}
.lay-ft-btn a{border-right:solid 1px #e3e3e3;color:#07a0d1;}

</style>

<script type="text/javascript">

//加载某条互动广场信息评论
function loadcomentbyid(iid){
    var comentmaxsize=10;
    var comentcurentpage=$("#comentcurentpage_"+iid).val();

    $.post("<%=basePath%>commentController/commentlistbyid",{random:Math.random(),iid:iid,comentmaxsize:comentmaxsize,comentcurentpage:comentcurentpage},function(rs){

        var msg=eval("("+rs+")");

        var cont=msg;

        var contnet=cont.replace(/\\"/g, "\'");
        var c=eval("("+contnet+")");

      var cotent=  getcomentcoenent(c.msg);
        console.info(cont);
        $("#comjinhua"+iid).html(cotent);

        $("#comentcurentpage_"+iid).val(parseInt(comentcurentpage)+1);
    });

}

function commentfun(id){

    var content =  $("#content"+id).val();

    if(content == ""){
        alert("说点什么吧");

    }else{

        if(content.length>=50 || content.length<=3  ){
           alert("字数限制在3-50字");

        }else{
            var data = "id="+id+"&content="+content;


            var comentcurentpage;
            var comentmaxsize;

            $.post("<%=basePath%>commentController/comentmsg",{random:Math.random(),iid:id,content:content,userid:"<%=userid%>"},function(rs){

               // alert("评论成功 ,获得15学币");
                var msg=eval("("+rs+")");
                alert(msg.msg);
                $("#content"+id).val("");
                var html='<dl id="dl_li">	<dt>'+nickname+'<span>刚刚</span></dt>	<dd>'+content+'</dd></dl>';


                //重新加载评论信息
                loadcomentbyid(id);
            });


        }
    }

}



var lock = false;

function updatePoint(p){
	 if(userAgent == "android"){
		  //var uri = 'gap://XXXClass.XXXmethod#'+p+userAgent;
	   	   // window.location = uri;
      	   javascript:contact.updatePoint(p);
       }else{
    	  // updatePoint(p);
    	 //  var uri = 'gap://XXXClass.XXXmethod#'+p ;
   	    window.location = uri;
       }
}
var     userAgent="android" ;
window.onload=function(){
	 userAgent =  navigator.userAgent ;
	if(userAgent.indexOf("iPhone") !=-1 ||    userAgent.indexOf("iPod") !=-1 ||   userAgent.indexOf("iphone") !=-1 ||      userAgent.indexOf("iPad") !=-1 ) {

	       userAgent ="ios";
    }else{
    	userAgent ="android";
    }


    //获取初始化数据
    loadcotent();



	  //ming.fullMsg.msg().html('加载到最多了').showAndAutoHide();
//我要发表评论
	$("#layout").on("click","[data-comadd]",function(e){
		var id=$(this).data("id");
		$("#comadd"+id).toggle();
		return false;
	});


	//api/comment/page

	//评论 查看更多
	$("#layout").on("click","[data-commore2]",function(e){
		var self=$(this);
		var page=self.data("page"); //获取页数
		var id=self.data("id");
		var totalcount=10;

		var comord=$("#comord"+id);
		var comjinhua = $("#comjinhua"+id);
		self.addClass('btnloading');
		 var currentPage = parseInt($("#comentcurentpage_"+id).val())+1;
		var data = "iid="+id+"&comentmaxsize="+totalcount+"&comentcurentpage="+currentPage;
		 var url ="<%=basePath%>commentController/commentlistbyid";

		 $.ajax({url:url,type:"GET",dataType:"html",data:data,success:function(d){

             var msg=eval("("+d+")");

             var cont=msg;

             var contnet=cont.replace(/\\"/g, "\'");
             var c=eval("("+contnet+")");

				 	if(c.length >0){
				 		var html =getcomentcoenent(c.msg);
				 		comjinhua.append(html);
						html="";
						//self.data("page",(parseInt(page)+1))
						self.data("page",currentPage);
						self.removeClass('btnloading');

						$("#comentcurentpage_"+id).val(currentPage);
				 	}else{
				 		self.html('没有评论了!');
				 		self.removeClass('btnloading');
				 	}
				 	
				 	

			}});


		return false;
	});

	//攒
	$("#layout").on("click","[data-statsu]",function(e){
	//	gurl.statsDefault2=gurl.statsDefault2;
		if(lock){
			return ;
		}
		var self=$(this);
        console.info(self);
	//	gp.flag=true;
		var _stats_u=self.data("statsu");
		var id=self.data("id");

		switch(_stats_u){
		case "like"://喜欢

			var url = "<%=basePath%>commentController/like";
			var date = $("#date").val();
			var userId = "<%=userid%>";


			var data = "?iid="+id+"&userid="+userId;
			lock = true;


            $.post(url+data,{random:Math.random()},function(rs){
                var msg=eval("("+rs+")");

                if(msg.success){
                    alert("喜欢成功,获得15学币");
                    var _like=$("#likenum_"+id);

                    _like.html(parseInt(_like)+1);
                }else{
                    alert("你已经喜欢过了...");
                }
            });

		 break;
	}
	});
	document.getElementById("layout").style.width=document.body.clientWidth+"px";
}
function getCommentHTML(json){
	var str="";
	var obj = eval("("+json+")");

	for(var i=0;i<obj.length;i++){
		var html='<dl id="dl_li">	<dt>'+obj[i].nickname+'<span>'+obj[i].create_date+'</span></dt>	<dd>'+obj[i].content+'</dd></dl>';
		str+=html;
	}
	return str;
}
function  toTop(){
	$("html,body").animate({scrollTop:$("#layout").offset().top},600);//1000是ms,也可以用slow代替
}

function toBack(){
	var nickname = $("#nickname").val();
	var userId = "<%=userid%>";
	var sso = $("#sso").val();
	//location.href="<%=basePath %>interactController/getinteractdetaillist?maxsize="+$("#maxsize").val()+"&currentpage="+$("#currentpage").val();

    var currentpage=$("#currentpage").val();
    currentpage=parseInt(currentpage);
    if(currentpage>1){
        currentpage--;
        $("#currentpage").val(currentpage);
        loadcotent();
    }else{
        currentpage=0;
        alert("没有啦");
    }

}



//获取文章内容

function loadcotent(){

    var pars=GetRequest();
    console.info(pars);
    $.post("<%=basePath %>interactController/getinteractdetaillist",{random:Math.random(),maxsize:$("#maxsize").val(),currentpage:$("#currentpage").val(),publishtime:pars.date},function(rs){

        var msg=eval("("+rs+")");

        var cont=msg;

        var contnet=cont.replace(/\\"/g, "\'");
        var c=eval("("+contnet+")");
        
        backcontent(c.msg);


    });

}

//获得评论内容
function getcomentcoenent(array){

    var conetent="";
    $.each(array,function(index,userbean){

        conetent+="<dl><dt>"+userbean.username+"<span>"+userbean.comenttime+"前</span></dt> <dd>"+userbean.commentmsg+"</dd></dl>";
        //隐藏字段
      

    });

    return conetent;
}
//返回内容
function backcontent(msg){


    $.each(msg,function(index,userbean){
        console.info(userbean);
        var cotent=" <article class='lay-list'><div class='list-box'><div class='art-txt'>";

        cotent+=userbean.content;

        cotent+="</div>";
        var islike=userbean.islike;
        //是否喜欢
        cotent+="<div class='css-reset list-btn list-like' style=' display: block;'>";
        cotent+=" <a class='btn-like' data-sharebox='true' data-id='"+userbean.id+"' href='javascript:void(0);' data-statsu='like' data-statsp='1' data-statsid='"+userbean.id+"'><span style='color: red;'>我很喜欢</span><em class='ico-like'></em></a>";
        cotent+="<div class='i-img'>";
        cotent+=" <img src='<%=basePath %>interact/images/btn-info2.png' width='27'>";
        cotent+=" </div>";
        cotent+=" <div class='i-count'>";
        cotent+="<em id='likenum_'"+userbean.id+">"+userbean.likecount+"</em>人喜欢</div></div>";

        //评论 头
        cotent +="<aside class='css-reset com-box' data-com='true'>";
        cotent +=" <div id='comlist"+index+"' class='com-list' data-comlist='true'>";

        cotent +="<input type='hidden' value='1' id='comentcurentpage_"+userbean.id+"'/>";
        
        cotent +=" <h3><div class='ico'></div></h3>";

         cotent+="<div id='comord"+index+"' data-comord='true'> </div>";
        cotent+="<div id='comjinhua"+userbean.id+"' class='com-jh'>";

        //评论内容

        cotent+= getcomentcoenent(userbean.comments);


        //评论 结尾

        cotent+="</div></div>";
        cotent+="<article></article>";


        //按钮

        cotent+="<div class='com-btn'>";
        cotent+="<a id='comcount"+index+"' data-commore2='true' data-page='1' data-totalcount='"+userbean.commentcout+"' data-id='"+userbean.id+"' href='javascript:void(0);'><span class='ico-h650'>评论<em class='comcount'>("+userbean.commentcout+" )</em></span></a><a data-id='"+index+"' data-comadd='true' href='javascript:void()'><span class='ico-h700'>说两句</span></a>";
        cotent+=" </div><div id='comadd"+index+"' class='com-add' style='display:none;'>";
        cotent+="<ul><li class='com-con-box'><div class='point'></div>";
        cotent+="<textarea id='content"+userbean.id+"' name='content' required='' placeholder='元芳，你怎么看？'></textarea></li>";
        cotent+="<li><a data-id="+index+"' data-submit='true' class='submit' href='javascript:commentfun(\""+userbean.id+"\");' id='contentlinkid_"+userbean.id+"' name='taglike' userid='"+userbean.id+"'>发布</a></li>";
        cotent+=" </ul></div> </aside></div></article>";


        $(".lay-art").append(cotent);
    });






}

</script>
<Script language="javascript">
    function GetRequest() {

        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
</Script>
<style type="text/css">
.jokeIndex .icoCommentTop, .jokeIndex .icoCommentRely, .jokeIndex .icoCommentReport {
height: 25px;
width: 20px;
}
.icoCommentTop {
background-position: 0px -392px;
}
.icoJokeAct {
vertical-align: top;
}
</style>
<!-- -->


</head>
<body>


<div class="layout" id="layout" style="width: 100%">
	<header class="css-reset lay-header" style="height: 59px;margin-bottom: 0px;">
	<h1 class="logo"><img src="<%=basePath%>interact/images/art_log.png" alt="头像" width="68" height="68" > </h1>
	<!--<a data-weibo="true" class="our" href="#"></a>-->
	<!--<a class="hy" href="#"><img src="images/hy.png" width="55" height="49"/></a>-->
	<!--<a class="hy-link" href="#"></a>-->
	<a href="javascript:void(0);" target="_blank" class="top_downloadBtn" id="dload_btn_box" data-appload="1"></a></header>
	<div class="lay-main">
		<div id="lay-ad1" class="css-reset lay-ad">
			<a href="/"><img src=""></a>
		</div>
		<!--lay-ad-->
		<section class="lay-art">


	     </section>
		<!--lay-art-->
		<div id="lay-ad2" class="css-reset lay-ad" pos="0l_12">
			<a href="/"><img src=""></a>
		</div>
		<!--lay-ad-->
		<div id="mod-app" class="css-reset" style="display:none;" pos="0l_12">
		</div>
		<!--mod-app-->
	 	<div class="css-reset lay-mod mod-tb" id="mod-tb" style="display:none;">
		</div>
	 </div>
	<!--lay-main-->
	<!--lay-ft-btn-->
	<footer class="lay-ft-btn"><a id="returntop" href="javascript:toBack()" style="width: 48%;float: left;">返回上一页</a> <a id="returntop" href="javascript:toTop()" style="width: 48%;float: left;"><span class="icon-arrow-up"></span>返回顶部</a></footer>
</div>

<input type="hidden" value="学生2141749" id="nickname">
<input type="hidden" value="<%=userid%>" id="userId" >
<input type="hidden" value="" id="sso">
<input type="hidden" value="2014-03-28" id="date">
<input type="hidden" value="10" id="maxsize">
<input type="hidden" value="1" id="currentpage">

<!--layout-->


<script src="<%=basePath %>interact/js/jquery.min.js"></script>

<script type="text/javascript">
    var scrollLoad = (function (options) {
        var defaults = (arguments.length == 0) ? { src: 'xSrc', time: 300} : { src: options.src || 'xSrc', time: options.time ||300};
        var camelize = function (s) {
            return s.replace(/-(\w)/g, function (strMatch, p1) {
                return p1.toUpperCase();
            });
        };
        this.getStyle = function (element, property) {
            if (arguments.length != 2) return false;
            var value = element.style[camelize(property)];
            if (!value) {
                if (document.defaultView && document.defaultView.getComputedStyle) {
                    var css = document.defaultView.getComputedStyle(element, null);
                    value = css ? css.getPropertyValue(property) : null;
                } else if (element.currentStyle) {
                    value = element.currentStyle[camelize(property)];
                }
            }
            return value == 'auto' ? '' : value;
        };
        var _init = function () {
            var offsetPage = window.pageYOffset ? window.pageYOffset : window.document.documentElement.scrollTop,
                offsetWindow = offsetPage + Number(window.innerHeight ? window.innerHeight : document.documentElement.clientHeight),
                docImg = document.images,
                _len = docImg.length;
            if (!_len) return false;
            for (var i = 0; i < _len; i++) {
                var attrSrc = docImg[i].getAttribute(defaults.src),
                    o = docImg[i], tag = o.nodeName.toLowerCase();
                if (o) {
                    postPage = o.getBoundingClientRect().top + window.document.documentElement.scrollTop + window.document.body.scrollTop; postWindow = postPage + Number(this.getStyle(o, 'height').replace('px', ''));
                    if ((postPage > offsetPage && postPage < offsetWindow) || (postWindow > offsetPage && postWindow < offsetWindow)) {
                        if (tag === "img" && attrSrc !== null) {
                            o.setAttribute("src", attrSrc);
                        }
                        o = null;
                    }
                }
            };
            window.onscroll = function () {
                setTimeout(function () {
                    _init();
                }, defaults.time);
            }
        };
        return _init();
    });
    scrollLoad();
</script>

</body></html>